home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / heaptut / examples / vulpkgs / vulpkg3 / vulprog3.c < prev   
Encoding:
C/C++ Source or Header  |  1999-01-22  |  780 b   |  41 lines

  1. /* dumb vulnerable program example, that uses function pointers */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. #include <string.h>
  7.  
  8. #define ERROR -1
  9. #define BUFSIZE 64
  10.  
  11. void goodfunc()
  12. {
  13.    printf("I'm the real goodfunc().  I have been called.\n");
  14.    return;
  15. }
  16.  
  17. int main(int argc, char **argv)
  18. {
  19.    static char buf[BUFSIZE];
  20.    static void (*funcptr)();
  21.  
  22.    if (argc <= 2)
  23.    {
  24.       fprintf(stderr, "Usage: %s <string1> <string2>\n", argv[0]);
  25.       exit(ERROR);
  26.    }
  27.  
  28.    funcptr = &goodfunc;
  29.    memset(buf, 0, BUFSIZE);
  30.  
  31.    printf("argv[1] = %p\n", argv[1]);
  32.    printf("buf = %p\n\n", buf);
  33.  
  34.    printf("before: funcptr = %p\n", funcptr);
  35.    strncpy(buf, argv[2], strlen(argv[2]));
  36.    printf("after: funcptr = %p\n\n", funcptr);
  37.  
  38.    (*funcptr)();
  39.    return 0;
  40. }
  41.